<template>
  <div class="main-container">
    <a-card class="layout-card">
      <template #title>
        <span style="font-weight: 700">评阅配置</span>
      </template>
      <a-form
        class="form"
        :model="addSubjectForm"
        name="basic"
        @submit="subFuncatio"
        ref="formRef"
        :rules="{}"
      >
        <a-row :gutter="24">
          <!-- <a-col :span="6">
            <a-form-item label="人工评阅客观题功能" name="kgtPyOpen">
              <a-tooltip
                :key="'#fadfvf'"
                title="开启后，标准卷的客观题，将会按设置的模式进行统计并展示"
                :color="'#fadfvf'"
                class="mr-10px"
              >
                <QuestionCircleOutlined />
              </a-tooltip>
              <a-switch
                :disabled="setStater"
                v-model:checked="addSubjectForm.kgtPyOpen"
                checked-children="开"
                un-checked-children="关"
              />
            </a-form-item>
          </a-col> -->

          <a-col :span="24"></a-col>
          <a-col :span="6">
            <a-form-item label="隐藏式复评功能(仅作用于主观题)" name="fpOpenFlag">
              <a-tooltip
                :key="'#fadfvf'"
                title="开启后，将按照设置的复评类型和复评参考值，在试评和正评时，进行隐藏式复评。复评产生的任意数据均不计入统分，仅对教师的评阅行为进行评分差异的检测，当超过规定的自评允许最大分差(含)时，则进入异常记录"
                :color="'#fadfvf'"
                class="mr-10px"
              >
                <QuestionCircleOutlined />
              </a-tooltip>
              <a-switch
                :disabled="setStater"
                v-model:checked="addSubjectForm.fpOpenFlag"
                checked-children="开"
                un-checked-children="关"
              />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="复评类型" name="fpDataType">
              <a-select
                v-model:value="addSubjectForm.fpDataType"
                :disabled="setStater || !addSubjectForm.fpOpenFlag"
                style="width: 100%"
                placeholder="请选择隐式复评类型"
                :options="fpOpenOptions"
              ></a-select>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item
              :label="addSubjectForm.fpDataType == 'RATE' ? '复评比例' : '复评数量'"
              name="fpDataCount"
            >
              <a-input-number
                :disabled="setStater || !addSubjectForm.fpOpenFlag"
                v-model:value="addSubjectForm.fpDataCount"
                :min="1"
                style="width: 100%"
                :placeholder="`请输入隐式${
                  addSubjectForm.fpDataType == 'RATE' ? '复评比例' : '复评数量'
                }`"
                :max="addSubjectForm.fpDataType == 'RATE' ? 100 : 100000"
              />
            </a-form-item>
          </a-col>

          <a-col :span="24"></a-col>
          <a-col :span="6">
            <a-form-item label="主观题强制设置得分点" name="bigScoreCutFlag">
              <a-tooltip
                :key="'#fadfvf'"
                title="开启后，在设置评阅标准时，将对最小答题单位超过参考值的主观题，强制要求设置得分点，且得单个分点分值也不允许超过规定值"
                :color="'#fadfvf'"
                class="mr-10px"
              >
                <QuestionCircleOutlined />
              </a-tooltip>
              <a-switch
                :disabled="setStater"
                v-model:checked="addSubjectForm.bigScoreCutFlag"
                checked-children="开"
                un-checked-children="关"
              />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="强制设置得分点阈值(含)" name="bigScoreValue">
              <a-input-number
                :disabled="setStater || !addSubjectForm.bigScoreCutFlag"
                v-model:value="addSubjectForm.bigScoreValue"
                :min="1"
                placeholder="请输入大分值参考值"
                style="width: 100%"
              />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="双评分差异常检测功能(仅作用于主观题)" name="spErrorOpenFlag">
              <a-tooltip
                :key="'#fadfvf'"
                title="开启后，评阅设置中将对双评模式试题进行分差设置，将对双评模式的题进行分差校验，超过设置的值，则进入异常记录中"
                :color="'#fadfvf'"
                class="mr-10px"
              >
                <QuestionCircleOutlined />
              </a-tooltip>
              <a-switch
                :disabled="setStater"
                v-model:checked="addSubjectForm.spErrorOpenFlag"
                checked-children="开"
                un-checked-children="关"
              />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="默认试评试卷份数" name="mockPyCount">
              <a-tooltip
                :key="'#fadfvf'"
                title="实际试卷份数不足时，按实际试卷份数处理"
                :color="'#fadfvf'"
                class="mr-10px"
              >
                <QuestionCircleOutlined />
              </a-tooltip>
              <a-input-number
                :disabled="setStater"
                v-model:value="addSubjectForm.mockPyCount"
                style="width: calc(100% - 50px)"
                placeholder="请输入试卷试评份数"
              />
            </a-form-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-item label="开启正评时,是否校验试评已完成" name="zpMustCpWorkedFlag">
              <a-tooltip
                :key="'#fadfvf'"
                title="开启后，须试评完成，才能进入正评环节"
                :color="'#fadfvf'"
                class="mr-10px"
              >
                <QuestionCircleOutlined />
              </a-tooltip>
              <a-switch
                :disabled="setStater"
                v-model:checked="addSubjectForm.zpMustCpWorkedFlag"
                checked-children="开"
                un-checked-children="关"
              />
            </a-form-item>
          </a-col> -->
          <!-- <a-col :span="24">
            <a-form-item label="评阅提交切图点击校验（客观题）" name="clickDtkqtCheck4KgtFlag">
              <a-tooltip
                :key="'#fadfvf'"
                title="开启后，评阅提交时，对是否每张切图均点击过进行校验，均点击过，才允许提交"
                :color="'#fadfvf'"
                class="mr-10px"
              >
                <QuestionCircleOutlined />
              </a-tooltip>
              <a-switch
                :disabled="setStater"
                v-model:checked="addSubjectForm.clickDtkqtCheck4KgtFlag"
                checked-children="开"
                un-checked-children="关"
              />
            </a-form-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-item label="评阅提交切图点击校验（主观题）" name="clickDtkqtCheck4ZgtFlag">
              <a-tooltip
                :key="'#fadfvf'"
                title="开启后，评阅提交时，对是否每张切图均点击过进行校验，均点击过，才允许提交"
                :color="'#fadfvf'"
                class="mr-10px"
              >
                <QuestionCircleOutlined />
              </a-tooltip>
              <a-switch
                :disabled="setStater"
                v-model:checked="addSubjectForm.clickDtkqtCheck4ZgtFlag"
                checked-children="开"
                un-checked-children="关"
              />
            </a-form-item>
          </a-col>
          <a-col :span="24"></a-col>

          <a-col :span="24" style="text-align: center; margin-top: 30px">
            <a-button type="primary" :loading="subloading" :disabled="setStater" html-type="submit">
              保存
            </a-button>
            <a-button type="" @click="setPageStale" style="margin-left: 30px">
              {{ setStater ? '编辑' : '取消' }}
            </a-button>
          </a-col>
        </a-row>
      </a-form>
    </a-card>
  </div>
</template>
<script lang="ts" setup>
import { ref, onMounted, watch, computed } from 'vue'
import { setConfigInfo } from '/@/api/system-manage/teacher-info'

import { useUserStoreWithOut } from '/@/store/modules/user'
const userStore = useUserStoreWithOut()
const addSubjectForm = computed(() => userStore.getSysConfig)

import { useMessage } from '/@/hooks/web/useMessage'

const { createMessage } = useMessage()
const setStater = ref<Boolean>(true)
const subloading = ref<Boolean>(false)

watch(
  () => addSubjectForm.value.fpOpenFlag,
  () => {
    addSubjectForm.value.fpDataType = undefined
    addSubjectForm.value.fpDataCount = undefined
    addSubjectForm.value.fpErrorOpenFlag = false
  }
)

watch(
  () => addSubjectForm.value.bigScoreCutFlag,
  () => {
    addSubjectForm.value.bigScoreValue = undefined
  }
)

let kgtPyTypeOptions = ref<any>([])
let fpOpenOptions = ref<any>([])
let zjDataOptions = ref<any>([])

const setPageStale = () => {
  if (!setStater.value) {
    userStore.setSysConfig()
  }
  setStater.value = !setStater.value
}
const formRef = ref()
/**
 * 设置评阅设置
 */
const subFuncatio = async () => {
  formRef.value.validateFields().catch(err => {
    if (!err.errorFields.length) {
      subloading.value = true
      setConfigInfo(addSubjectForm.value)
        .then((res: any) => {
          if (res.code == 200) {
            createMessage.success('保存成功')
            setStater.value = true
          } else {
            createMessage.error(res.message)
          }
        })
        .finally(() => {
          subloading.value = false
        })
    }
  })
}

import { getDictionaryList } from '/@/views/teacher/home/index'

onMounted(async () => {
  // 获取评阅设置

  await getDictionaryList('kgtPyType', kgtPyTypeOptions)
  await getDictionaryList('fpDataType', fpOpenOptions)
  await getDictionaryList('zjDataType', zjDataOptions)
})
</script>

<style lang="less" scoped>
.main-container {
  // height: @c_height;
  .layout-card {
    height: 100%;
    border-radius: 8px;
    margin-bottom: 30px;
  }
}
</style>
